<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>开关灯泡</title>
</head>
<body>
    <img id="light" src="img/off.gif" alt="灯灭"">
    <script>
        var light = document.getElementById("light");
        var flag = false;
        light.onclick=function{
            if(flag){
                light.src="./image/off.gif";
                flag = false;
            }else {
                light.src="./image/on.gif";
                flag = true;
            }
        }

    </script>
</body>
</html>